/* 零件表相关api */

import http from "@/util/http"
import store from "../store/index"

/* 获取所有零件表信息 */
export function getPartsData(page, data, isChooing) {
    if (!isChooing) {
        return http.post(`/material/conditionSearch/${page}`, {})
    }
    return http.post(`/material/conditionSearch/${page}`,
        {
            "createTime": data.time,
            "maxPrice": data.maxPrice,
            "minPrice": data.minPrice,
            "name": data.name,
            "signId": data.signId,
            "specification": data.specification,
        }
    )
}

/* 根据ID获取零件表信息 */
export function getPartsDataById(id) {
    return http.get(`/material/getMaterialById/${id}`)
}

/* 获取零件名称 */
export function getPartsName() {
    return http.get(`/material/name`);
}

/* 获取规格名称 */
export function getSpecification() {
    return http.get(`/material/specification`);
}

/* 新增零件信息 */
export function addPart(data) {
    return http.post(`/material/insertMaterial`, {
        createTime: data.createTime,
        id: data.id,
        name: data.name,
        number: data.number,
        price: data.price,
        signId: data.signId,
        specification: data.specification,
        surplus: data.surplus,
        updateTime: data.updateTime,
        used: data.used,
    })
}

/* 修改零件信息 */
export function updatePartData(data) {
    return http.post(`/material/updateMaterial`,
        {
            id: data.id,
            name: data.name,
            price: data.price,
            specification: data.specification,
        }
    )
}

/* 删除零件 */
export function deletePart(id) {
    return http.get(`/material/deleteMaterial/${id}`)
}

/* 判断名称和规格是否存在 */
export function checkIsPart(data) {
    return http.post(`/material/checkNameAndSpc`, {
        name: data.name,
        specification: data.specification
    })
}